local extension = Package:new("test3")
extension.extensionName = "aj_test"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["test3"] = "测试·三",
}

local ren = General:new(extension, "test3__ren", "test_hui", 3,4)

Fk:loadTranslationTable{
  ["test3__ren"] = "刃",--名字
  ["#test3__ren"] = "业途游魂",--称号
  ["designer:test3__ren"] = "zuozhe",--作者
  ["cv:test3__ren"] = "cv",--cv
  ["illustrator:test3__ren"] = "huashi",--画师

  ['~test3__ren'] = '这次能成功吗……',
}

local zhili = fk.CreateTriggerSkill{
  name = "test3__zhili",
  frequency = Skill.Compulsory,
  events ={fk.Damaged},
  can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self.name) and ((player.maxHp - player.hp) > 0)
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(math.min((player.maxHp - player.hp), 2), self.name)
  end,
}

local zhili_draw = fk.CreateTriggerSkill{
  name = "#test3__zhili_draw",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = (player.maxHp - player.hp)
    player:broadcastSkillInvoke("test3__zhili")
  end,
}

local zhili_maxcards = fk.CreateMaxCardsSkill{
  name = "#test3__zhili_maxcards",
  main_skill = zhili,
  fixed_func = function(self, player)
    if player:hasSkill(zhili) then
      return (player.maxHp - player.hp)
    end
  end,
}

Fk:loadTranslationTable{
  ["test3__zhili"] = "支离",
  [":test3__zhili"] = "锁定技，当你受到伤害后，你摸X张牌（至多为二）；你的摸牌阶段摸牌数及手牌上限均为X（X为你已损失的体力值）。",

  ["#test3__zhili_draw"] = "支离",

  ["$test3__zhili1"] = "剑下不必留情。",
  ["$test3__zhili2"] = "可惜…还活着。",
  ["$test3__zhili3"] = "你会带给我惊喜吗……",
}


local shuhu = fk.CreateTriggerSkill{
  name = "test3__shuhu",
  events ={fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and
      player:usedSkillTimes(self.name) == 0 and data.card.is_damage_card and
      #TargetGroup:getRealTargets(data.tos) == 1 and 
      TargetGroup:getRealTargets(data.tos)[1] ~= player.id 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    TargetGroup:pushTargets(data.tos,player.id)
    local n = 3
    local all = {"#test3__shuhu-1","#test3__shuhu-2","#test3__shuhu-3"}
    local ask = table.clone(all)

    local tos = room:getUseExtraTargets(data,false)
    if not player:isWounded() then return end
    if #tos == 0 then
      table.removeOne(ask,"#test3__shuhu-1")
      n = n - 1
    end
    local m = math.min(player.maxHp - player.hp,n)
    local choices = room:askForChoices(player,ask,m,m,self.name,nil,false,nil,all)
    if table.contains(choices,"#test3__shuhu-1") then
      tos = room:askForChoosePlayers(player,tos,1,1,"#test3__shuhu-ask1",self.name)
      if #tos > 0 then
        TargetGroup:pushTargets(data.tos,tos)
      end
    end
    if table.contains(choices,"#test3__shuhu-2") then
      if room:askForSkillInvoke(player,self.name,nil,"#test3__shuhu-ask2") then
        data.additionalDamage = (data.additionalDamage or 0) + 1
      else
        data.disresponsiveList = data.disresponsiveList or {}
        table.insertTableIfNeed(data.disresponsiveList,table.map(room:getAlivePlayers(),Util.IdMapper))
      end
    end
    if table.contains(choices,"#test3__shuhu-3") then
      for _, p in ipairs(room:getAlivePlayers()) do
        if not p:isNude() and not p.dead and table.contains(TargetGroup:getRealTargets(data.tos),p.id) then
          local card = room:askForCardChosen(player, p, "he", self.name,"#test3__shuhu-ask3::"..p.id)
          room:throwCard(card,self.name,p,player)
        end
      end
    end
  end,
}

Fk:loadTranslationTable{
["test3__shuhu"] = "倏忽",
[":test3__shuhu"] = "每回合限一次，当你使用伤害牌时，若目标数为1且不为你，你可将自身加入此牌目标并选择任意X项依序执行：1.额外指定1个目标；2.此牌伤害+1或不可响应；3.弃置所有目标一张牌（X为你已损失的体力值）。 ",

["#test3__shuhu-1"] = "额外指定1个目标",
["#test3__shuhu-2"] = "此牌伤害+1或不可响应",
["#test3__shuhu-3"] = "弃置所有目标一张牌",

["#test3__shuhu-ask1"] = "倏忽：额外指定1个目标",
["#test3__shuhu-ask2"] = "倏忽：你可以令此牌伤害+1，或取消后令此牌不可响应",
["#test3__shuhu-ask3"] = "倏忽：弃置%dest一张牌",


["$test3__shuhu1"] = "死兆…将至！",
["$test3__shuhu2"] = "其势…已成！",
["$test3__shuhu3"] = "彼岸…葬送！",
}

zhili:addRelatedSkill(zhili_maxcards)
zhili:addRelatedSkill(zhili_draw)
ren:addSkill(zhili)
ren:addSkill(shuhu)


local lingke = General:new(extension, "test3__lingke", "test_feng", 3,3, General.Female)

Fk:loadTranslationTable{
  ["test3__lingke"] = "玲可",--名字
  ["#test3__lingke"] = "雪原探险家",--称号
  ["designer:test3__lingke"] = "zuozhe",--作者
  ["cv:test3__lingke"] = "cv",--cv
  ["illustrator:test3__lingke"] = "huashi",--画师

  ['~test3__lingke'] = '哥…姐……',
}

local guantou = fk.CreateActiveSkill{
  name = "test3__guantou",
  prompt = "#test3__guantou",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name,Player.phase) == 0
  end,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = room:askForCardChosen(player, target, "he", self.name,"#test3__guantou-ask::"..target.id)
    room:throwCard(card,self.name,target,player)
    if target.maxHp < 5 then
      room:changeMaxHp(target,1)
    else
      target:drawCards(2,self.name)
    end
  end,
}

Fk:loadTranslationTable{
  ["test3__guantou"] = "罐头",
  [":test3__guantou"] = "出牌阶段限一次，你可以弃置一名角色的一张牌，然后若其体力上限小于5，其增加一点体力上限，否则其摸两张牌。",

  ["#test3__guantou"] = "罐头：你可以弃置一名角色的一张牌，令其增加体力上限或摸两张牌",
  ["#test3__guantou-ask"] = "罐头：弃置%dest一张牌",

  ["$test3__guantou1"] = "补充点盐分。",
  ["$test3__guantou2"] = "放松深呼吸。",
}

local qiusheng = fk.CreateActiveSkill{
  name = "test3__qiusheng",
  prompt = "#test3__qiusheng",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name,Player.phase) == 0
  end,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):isWounded()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:recover({
      who = target,
      num = 1,
      recoverBy = player,
      skillName = "test3__qiusheng",
    })
    local tos = table.filter(room:getAlivePlayers(),function (p)
      return p:distanceTo(target) == 1 and not p:isKongcheng()
    end)
    if #tos > 0 then
      local ts = room:askForChoosePlayers(player,table.map(tos,Util.IdMapper),1,1,"#test3__qiusheng-ask",self.name,false)
      if #ts > 0 then
        local t = room:getPlayerById(ts[1])
        local cards = t:getCardIds("h")
        room:showCards(cards)
        while not target.dead do
          if #cards == 0 then break end
          room:delay(300)
          local card = Fk:getCardById(cards[1])
          if card.trueName == "slash" and table.contains(t:getCardIds("h"),card.id) and
          t:canUseTo(card, target, {bypass_distances = true, bypass_times = true}) then
            room:useCard({
              card = card,
              from = t.id,
              tos = {{target.id}},
              extraUse = true,
            })
          end
          table.remove(cards, 1)
        end
      end
    end
  end,
}

Fk:loadTranslationTable{
  ["test3__qiusheng"] = "求生",
  [":test3__qiusheng"] = "出牌阶段限一次，你可以令一名已受伤的角色回复1点体力，然后指定距离其为1以内的一名其他角色，后者展示手牌并将其中的【杀】依次对回复体力的角色使用。",

  ["#test3__qiusheng"] = "求生：你可以令一名已受伤的角色回复1点体力",

  ["$test3__qiusheng1"] = "目标标本出现，准备采集。",
  ["$test3__qiusheng2"] = "为了去往远方……",
}

lingke:addSkill(guantou)
lingke:addSkill(qiusheng)

local jingliu = General:new(extension, "test3__jingliu", "test_hui", 4,4, General.Female)

Fk:loadTranslationTable{
  ["test3__jingliu"] = "镜流",--名字
  ["#test3__jingliu"] = "月有薄蚀",--称号
  ["designer:test3__jingliu"] = "zuozhe",--作者
  ["cv:test3__jingliu"] = "cv",--cv
  ["illustrator:test3__jingliu"] = "huashi",--画师

  ['~test3__jingliu'] = '终于，解脱了…',
}

local ningyue = fk.CreateTriggerSkill{
  name = "test3__ningyue",
  anim_type = "defensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local ids = {}
      local room = player.room
      local event_id = room.logic:getCurrentEvent().id

      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          if move.moveReason == fk.ReasonDiscard and move.from and move.proposer 
          --and move.from ~= move.proposer 
          then
            
            if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
              for _, m in ipairs(e.data) do --完全一致的筛选
                if m.toArea == Card.DiscardPile then
                  if m.moveReason == fk.ReasonDiscard and m.from and m.proposer --and m.from ~= m.proposer
                  and m.from == move.from then
                    for _, info in ipairs(m.moveInfo) do
                      if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
                      Fk:getCardById(info.cardId).color == Card.Black and 
                      e.id ~= event_id then --
                        return true
                      end
                    end
                  end
                end
              end
            end, Player.HistoryRound) > 0 then return end
            
            
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
              Fk:getCardById(info.cardId).color == Card.Black and
              room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end
      ids = U.moveCardsHoldingAreaCheck(room, ids)
      if #ids > 0 then
        self.cost_data = {ids = ids}
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local ids = table.simpleClone(self.cost_data.ids)
    if #ids > 0 then
      local use = U.askForUseVirtualCard(room,player,"ice__slash",ids,self.name,"#test3__ningyue",nil,nil,nil,nil,nil,true)
      self.cost_data = {use = use}
      return use
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:useCard(self.cost_data.use)
  end,
}

Fk:loadTranslationTable{
  ["test3__ningyue"] = "凝月",
  --[":test3__ningyue"] = "当一名角色每轮首次被弃置黑色牌后，你可将之当冰【杀】使用。",
  [":test3__ningyue"] = "一名角色于本轮首次因弃置失去黑色牌后，你可将之当冰【杀】使用。",

  ["#test3__ningyue"] = "凝月：你可以使用冰【杀】",

  ["$test3__ningyue1"] = "我以月色为剑。",
  ["$test3__ningyue2"] = "身外浮名，如云散尽。",
  ["$test3__ningyue3"] = "你无处可逃。",
}

jingliu:addSkill(ningyue)


local tuopazhangzhang = General:new(extension, "test3__tuopazhangzhang", "test_lie", 3,3, General.Female)

Fk:loadTranslationTable{
  ["test3__tuopazhangzhang"] = "托帕账账",--名字
  ["#test3__tuopazhangzhang"] = "落日条款",--称号
  ["designer:test3__tuopazhangzhang"] = "zuozhe",--作者
  ["cv:test3__tuopazhangzhang"] = "cv",--cv
  ["illustrator:test3__tuopazhangzhang"] = "huashi",--画师

  ['~test3__tuopazhangzhang'] = '还没填…事假申请……',
}

local zhushi = fk.CreateTriggerSkill{
  name = "test3__zhushi",
  anim_type = "defensive",
  events ={fk.Damage},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self.name) and player:usedSkillTimes(self.name) == 0 and
      not player:isNude() and
      data.from and (data.from.phase ~= Player.Play or
      #player.room.logic:getEventsOfScope(GameEvent.Phase, 999, function (e)
        return e.data[1] == data.from and e.data[2] == Player.Play
      end, Player.HistoryRound) ~= 1)
      and data.damage == 1 and not data.to.dead 
  end,
  on_cost = function (self, event, target, player, data)
    --return #player.room:askForDiscard(player,1,1,true,self.name,true,nil,"#test3__zhushi::"..data.to.id) > 0
    local damage_card = table.filter(player:getCardIds("he"),function (id)
      return Fk:getCardById(id).is_damage_card
    end)
    local pattern = ".|.|.|.|.|.|"..table.concat(damage_card,",")
    return #damage_card > 0 and #player.room:askForDiscard(player,1,1,true,self.name,true,pattern,"#test3__zhushi::"..data.to.id) > 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:damage({
        from = player,
        to = data.to,
        damage = 1,
        damageType = data.damageType,
        skillName = self.name,
      })
  end,
}

Fk:loadTranslationTable{
  ["test3__zhushi"] = "猪市",
  --[":test3__zhushi"] = "每回合限一次，当一名角色于其每轮第一个出牌阶段以外的阶段造成不大于1的伤害后，你可以弃一张牌并对受伤者造成一点同属性的伤害。",
  [":test3__zhushi"] = "每回合限一次，当一名角色于其每轮第一个出牌阶段以外的阶段造成不大于1的伤害后，你可以弃置一张伤害牌并对受伤者造成一点同属性的伤害。",

  ["#test3__zhushi"] = "猪市：你可以弃置一张伤害牌对%dest造成一点同属性的伤害",

  ["$test3__zhushi1"] = "连本带息还债！",
  ["$test3__zhushi2"] = "账账，狠狠地砸！",
}

local zhangfu = fk.CreateTriggerSkill{
  name = "test3__zhangfu",
  mute = true,
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and table.contains({Player.Start, Player.Draw, Player.Finish}, player.phase)
  end,
  on_cost = function (self, event, target, player, data)
    local u = U.askForPlayCard(player.room,player,nil,nil,self.name,nil,nil,true)
    self.cost_data = {u = u}
    return u
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke(self.name,math.random(1,2))
    player.room:notifySkillInvoked(player, self.name)
    player.room:useCard(self.cost_data.u)
  end,
}

local zhangfu_use = fk.CreateTriggerSkill{
  name = "#test3__zhangfu_use",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase ~= Player.NotActive
  end,
  on_use = function (self, event, target, player, data)
    player.room:setPlayerMark(player,"test3__zhangfu-phase",1)
    player:endPlayPhase()
  end,
}

local zhangfu_skip = fk.CreateTriggerSkill{
  name = "#test3__zhangfu_skip",
  mute = true,
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and table.contains({Player.Judge, Player.Discard}, data.to)
  end,
  on_use = function (self, event, target, player, data)
    --player:skip(data.to)
    return true
    --data.skipped = true
  end,
}

local zhangfu_prohibit = fk.CreateProhibitSkill{
  name = "#test3__zhangfu_prohibit",
  frequency = Skill.Compulsory,
  prohibit_use = function(self, player, card)
    return player:getMark("test3__zhangfu-phase") > 0
  end,
}

local zhangfu_draw = fk.CreateTriggerSkill{
  name = "#test3__zhangfu_draw",
  mute = true,
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local chong = true  --牌名重复就为假
      local card_name = {}
      local use_card = 0
      local n = #player.room.logic:getEventsOfScope(GameEvent.Phase, 999, function(e)
        if chong and e.data[1] == player and table.contains({Player.Start, Player.Draw, Player.Play, Player.Finish}, e.data[2]) then
          if chong and #e:searchEvents(GameEvent.UseCard, 999, function(u)
            local use = u.data[1]
            if chong and use.from == player.id then
              if table.contains(card_name,use.card.trueName) then
                chong = false
              else
                table.insert(card_name,use.card.trueName)
                --p(card_name)
              end
              return chong
            end
          end) > 0 then
            use_card = use_card + 1
          end
          return chong
        end
      end, Player.HistoryTurn)
      --print(n,use_card)
      return chong and n == use_card
    end
  end,
  on_use = function (self, event, target, player, data)
    player.room:notifySkillInvoked(player, "test3__zhangfu")
    player:broadcastSkillInvoke("test3__zhangfu",3)
    player:drawCards(2,self.name)
  end,
  --[[
  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_refresh = function (self, event, target, player, data)
    local n = #player.room.logic:getEventsOfScope(GameEvent.Phase, 999, function(e)
      print(Util.PhaseStrMapper(e.data[2]))
      return e.data[1] == player
    end, Player.HistoryTurn)
    print(n)
  end,
  --]]
}

Fk:loadTranslationTable{
  ["test3__zhangfu"] = "涨幅",
  [":test3__zhangfu"] = "锁定技，你没有判定阶段与弃牌阶段，且你于你的每个阶段都能且仅能使用一张牌。回合结束后，若你本回合于所有阶段均使用了牌且这些牌名均不同，你摸两张牌。",

  ["#test3__zhangfu_use"] = "涨幅",
  ["#test3__zhangfu_skip"] = "涨幅",
  ["#test3__zhangfu_prohibit"] = "涨幅",
  ["#test3__zhangfu_draw"] = "涨幅",
  ["#test3__zhangfu"] = "涨幅：你可以使用一张牌",

  ["$test3__zhangfu1"] = "开始吧，资产评估。",
  ["$test3__zhangfu2"] = "行情扑朔迷离",
  ["$test3__zhangfu3"] = "这个项目就算结了。",
}

tuopazhangzhang:addSkill(zhushi)
zhangfu:addRelatedSkill(zhangfu_draw)
zhangfu:addRelatedSkill(zhangfu_use)
zhangfu:addRelatedSkill(zhangfu_skip)
zhangfu:addRelatedSkill(zhangfu_prohibit)
tuopazhangzhang:addSkill(zhangfu)


local huohuo = General:new(extension, "test3__huohuo", "test_feng", 3,3, General.Female)

Fk:loadTranslationTable{
  ["test3__huohuo"] = "藿藿",--名字
  ["#test3__huohuo"] = "令奉贞凶",--称号
  ["designer:test3__huohuo"] = "zuozhe",--作者
  ["cv:test3__huohuo"] = "cv",--cv
  ["illustrator:test3__huohuo"] = "huashi",--画师

  ['~test3__huohuo'] = '投…投降……',
}

local qieqie = fk.CreateTriggerSkill{
  name = "test3__qieqie",
  mute = true,
  frequency = Skill.Compulsory,
  events ={fk.CardUsing,fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:hasSkill("test3__weiling") and player == target and
    data.card.is_damage_card and not table.contains(data.card.skillNames,"test3__qianshen")
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, self.name)
    if event == fk.CardUsing then
      player:broadcastSkillInvoke(self.name,1)
    else
      player:broadcastSkillInvoke(self.name,math.random(2,4))
    end
    data.extra_data = data.extra_data or {}
    data.extra_data.test3__qieqie = true
    player.room:handleAddLoseSkills(player,"test3__weiling")
  end,
  refresh_events = {fk.CardUseFinished},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and player:hasSkill("test3__weiling") and --player == target and
    data.extra_data and data.extra_data.test3__qieqie
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player,"-test3__weiling")
  end,
}

Fk:loadTranslationTable{
  ["test3__qieqie"] = "怯怯",
  [":test3__qieqie"] = "锁定技，当一张伤害牌不因“遣神”被你使用或指定你为目标后，你获得“尾灵”直到此牌结算完成。",

  ["$test3__qieqie1"] = "说不定我也能做到…",
  ["$test3__qieqie2"] = "不要啊救命啊——",
  ["$test3__qieqie3"] = "尾巴救救！",
  ["$test3__qieqie4"] = "你、你们不要过来啊…",
}

local qianshen = fk.CreateTriggerSkill{
  name = "test3__qianshen",
  events ={fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.who == player and target == player 
  end,
  on_cost = function (self, event, target, player, data)
    local u = player.room:askForUseRealCard(player,{data.card.id},self.name,nil,{expand_pile = {data.card.id}},nil,true)
    self.cost_data = {u = u}
    return u
  end,
  on_use = function(self, event, target, player, data)
    local u = self.cost_data.u
    table.insertIfNeed(u.card.skillNames,"test3__qianshen")
    player.room:useCard(u)
  end,
}


local qianshen_hp = fk.CreateTriggerSkill{
  name = "#test3__qianshen_hp",
  events ={fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    local event_id = player.room.logic:getCurrentEvent().parent.id --父事件
    return player:hasSkill(self) and data.from == player.id and table.contains(data.card.skillNames,"test3__qianshen")
    and #player.room.logic:getEventsByRule(GameEvent.Damage,1,function (e)
          local use = e.data[1]
          return use.card.id == data.card.id
        end,event_id) > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local ps = table.filter(room:getAlivePlayers(),function (p)
      return p:isWounded()
    end)
    if #ps > 0 then
      local p = room:askForChoosePlayers(player,table.map(ps,Util.IdMapper),1,1,"#test3__qianshen_hp-ask","test3__qianshen")
      self.cost_data = {p = p[1]}
      return #p > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:recover({
      who = player.room:getPlayerById(self.cost_data.p),
      num = 1,
      recoverBy = player,
      skillName = "test3__qianshen",
    })
  end,
}

Fk:loadTranslationTable{
  ["test3__qianshen"] = "遣神",
  [":test3__qianshen"] = "当你的判定牌生效后，你可以使用之，此牌结算后，若造成了伤害，你可以令一名角色回复1点体力。 ",

  ["#test3__qianshen_hp"] = "遣神",
  ["#test3__qianshen_hp-ask"] = "遣神：你可以令一名角色回复1点体力",

  ["$test3__qianshen1"] = "灵符…保命…",
  ["$test3__qianshen2"] = "驱邪…缚魅…",
}

local weiling = fk.CreateTriggerSkill{
  name = "test3__weiling",
  mute = true,
  frequency = Skill.Compulsory,
  on_acquire = function (self, player, is_start)
    player.room:notifySkillInvoked(player, self.name)
    player:broadcastSkillInvoke(self.name,math.random(1,2))
    local judge = {
      who = player,
      reason = "test3__weiling",
      pattern = ".",
    }
    player.room:judge(judge)
  end,
  on_lose = function (self, player, is_death)
    player.room:notifySkillInvoked(player, self.name)
    player:broadcastSkillInvoke(self.name,math.random(3,4))
    local cards = player:getCardIds("h")
    if #cards > 0 then
      player:showCards(cards)
      cards = table.filter(cards,function (id)
        return Fk:getCardById(id).is_damage_card
      end)
      if #cards > 0 then
        player.room:recastCard(cards,player,self.name)
      end
    end
  end,
}


Fk:loadTranslationTable{
  ["test3__weiling"] = "尾灵",
  [":test3__weiling"] = "锁定技，当你获得此技能时，你进行判定；当你失去此技能时，你展示手牌并重铸所有伤害牌。",

  ["$test3__weiling1"] = "藿藿：非、非得战斗吗？尾巴：对喽~别逃啊~",
  ["$test3__weiling2"] = "尾巴：有老子在，你怕什么？",
  ["$test3__weiling3"] = "呜好疼…",
  ["$test3__weiling4"] = "这下肯定做不到了…",
}


huohuo:addSkill(qieqie)
qianshen:addRelatedSkill(qianshen_hp)
huohuo:addSkill(qianshen)
huohuo:addRelatedSkill(weiling)


local yinzhi = General:new(extension, "test3__yinzhi", "test_shi", 4)

Fk:loadTranslationTable{
  ["test3__yinzhi"] = "银枝",--名字
  ["#test3__yinzhi"] = "荆冠芳勋",--称号
  ["designer:test3__yinzhi"] = "zuozhe",--作者
  ["cv:test3__yinzhi"] = "cv",--cv
  ["illustrator:test3__yinzhi"] = "huashi",--画师

  ['~test3__yinzhi'] = '没找到…「祂」……',
}

local jingguan = fk.CreateTriggerSkill{
  name = "test3__jingguan",
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and
    player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player,1,self.name)
    if not player.dead then
      room:addPlayerMark(player, MarkEnum.BypassDistancesLimit .. "-turn")
      room:setPlayerMark(player,"@@test3__jingguan-turn",1)      
      if table.find(room:getOtherPlayers(player),function (p)
            return p.hp <= player.hp
          end) == nil then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name,
        })        
      end
    end
  end,
}

local jingguan_delay = fk.CreateTargetModSkill{
  name = "#test3__jingguan_delay",
  residue_func = function (self, player, skill, scope, card, to)
    if skill.trueName == "slash_skill" and player:getMark("@@test3__jingguan-turn") > 0 then
      return 1
    end
  end,
}

Fk:loadTranslationTable{
  ["test3__jingguan"] = "荆冠",
  [":test3__jingguan"] = "准备阶段，你可以失去一点体力，若如此做，本回合你使用【杀】的次数+1且使用牌无距离限制；若此时你的体力值为场上唯一最少，你回复一点体力。",

  ["#test3__jingguan_delay"] = "荆冠",
  ["@@test3__jingguan-turn"] = "荆冠",

  ["$test3__jingguan1"] = "我向一朵玫瑰起誓。",
  ["$test3__jingguan2"] = "遵循纯美骑士的职责。 ",
}


local shouxun = fk.CreateTriggerSkill{
  name = "test3__shouxun",
  mute = true,
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self.name) and player.phase == Player.Play and player:isWounded()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getNCards(2)
    room:moveCards({
      ids = ids,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
      proposer = player.id,
    })
    room:notifySkillInvoked(player, self.name)
    player:broadcastSkillInvoke(self.name,math.random(1,2))
    room:delay(1000)
    local card = U.askforChooseCardsAndChoice(player, ids, {"OK"}, "test3__shouxun", "#test3__shouxun")
    for _, c in ipairs(ids) do
      if c == card[1] then
        room:obtainCard(player, c, true, fk.ReasonJustMove,player.id,"test3__shouxun")
      else
        room:setPlayerMark(player,"@test3__shouxun-turn",Fk:getCardById(c):getTypeString())
        if room:getCardArea(c) == Card.Processing then
          room:moveCardTo(c, Card.DrawPile, nil, fk.ReasonJustMove, "test3__shouxun", nil, true, player.id)
        end
      end
    end
  end,
}
local shouxun_end = fk.CreateTriggerSkill{
  name = "#test3__shouxun_end",
  mute = true,
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shouxun.name) and 
    player.phase == Player.Finish and player:getMark("@test3__shouxun-turn") ~= 0
    and (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card:getTypeString() == player:getMark("@test3__shouxun-turn")
    end,  Player.HistoryTurn) > 1)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2,self.name)
    local t = room:askForChoosePlayers(player,table.map(room:getOtherPlayers(player),Util.IdMapper),1,1,"#test3__shouxun-p","test3__shouxun",false)
    if #t > 0 then
      room:notifySkillInvoked(player, "test3__shouxun")
      player:broadcastSkillInvoke("test3__shouxun",math.random(3,4))
    room:handleAddLoseSkills(player,"-test3__shouxun")
    room:handleAddLoseSkills(room:getPlayerById(t[1]),"test3__shouxun")
    end
  end,
}

local shouxun_start = fk.CreateTriggerSkill{
  name = "#test3__shouxun_start",
  mute = true,
  events ={fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(shouxun.name) and not table.contains({player.general,player.deputyGeneral}, "test3__yinzhi")
  end,
  on_cost = function (self, event, target, player, data)
    local p = table.find(player.room:getOtherPlayers(player),function (t)
      return table.contains({t.general,t.deputyGeneral}, "test3__yinzhi")
    end)
    self.cost_data = {p = p}
    return p
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, "test3__shouxun")
    player:broadcastSkillInvoke("test3__shouxun",math.random(3,4))
    room:handleAddLoseSkills(player,"-test3__shouxun")
    room:handleAddLoseSkills(self.cost_data.p,"test3__shouxun")
  end,
}

Fk:loadTranslationTable{
["test3__shouxun"] = "授勋",
[":test3__shouxun"] = "出牌阶段开始时，若你已受伤，你可以展示牌堆顶的两张牌，获得其中一张牌并记录另一张的类型；结束阶段，若你本回合使用了至少两张记录类型的牌，你摸两张牌并交出“授勋”。每轮开始时，你将“授勋”交给银枝。",

["#test3__shouxun_end"] = "授勋",
["#test3__shouxun_start"] = "授勋",
["@test3__shouxun-turn"] = "授勋",
["#test3__shouxun"] = "授勋：你获得其中一张牌并记录另一张的类型",
["#test3__shouxun-p"] = "授勋：将“授勋”交给一名角色",

["$test3__shouxun1"] = "荣光在上。",
["$test3__shouxun2"] = "再次见到那道光芒之前……",
["$test3__shouxun3"] = "彷徨的人啊，你的目光正看向何方？",
["$test3__shouxun4"] = "我们定会于宇宙某处偶然相逢。",
}

jingguan:addRelatedSkill(jingguan_delay)
yinzhi:addSkill(jingguan)
shouxun:addRelatedSkill(shouxun_start)
shouxun:addRelatedSkill(shouxun_end)
yinzhi:addSkill(shouxun)


local hanya = General:new(extension, "test3__hanya", "test_xie", 3,3, General.Female)

Fk:loadTranslationTable{
  ["test3__hanya"] = "寒鸦",--名字
  ["#test3__hanya"] = "冥谶天笔",--称号
  ["designer:test3__hanya"] = "zuozhe",--作者
  ["cv:test3__hanya"] = "cv",--cv
  ["illustrator:test3__hanya"] = "huashi",--画师

  ['~test3__hanya'] = '姐姐，我…… ',
}


local wennie = fk.CreateTriggerSkill{
  name = "test3__wennie",
  frequency = Skill.Limited,
  events ={fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local t = player.room:askForChoosePlayers(player,table.map(player.room:getAlivePlayers(),Util.IdMapper),1,1,"#test3__wennie","test3__wennie")
    self.cost_data = {t = t[1]}
    return #t > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local t = room:getPlayerById(self.cost_data.t)
    room:setPlayerMark(t,"@@test3__wennie",1)
    room:setPlayerMark(player,"test3__wennie",t.id)
    room:setPlayerMark(player,"@test3__wennie",Fk:translate(t.general))
  end,
  refresh_events ={fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@test3__wennie") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    if player.phase == Player.NotActive and data.card.type == Card.TypeBasic then
      player.room:setPlayerMark(player,"@@test3__wennie_cheng",1)
    elseif player.phase ~= Player.NotActive and data.card.type == Card.TypeTrick then
      player.room:setPlayerMark(player,"@@test3__wennie_fu",1)
    end
  end,
}

Fk:loadTranslationTable{
  ["test3__wennie"] = "问孽",
  [":test3__wennie"] = "限定技，每轮开始时，你可指定一名角色，当其于回合外使用基本牌/回合内使用锦囊牌时，其获得“承”/“负”（“承”/“负”各至多为1）。",

  ["#test3__wennie"] = "问孽：你可以令一名角色使用牌时获得“承”/“负”",
  ["@test3__wennie"] = "问孽",
  ["@@test3__wennie"] = "问孽",
  ["@@test3__wennie_cheng"] = "承",
  ["@@test3__wennie_fu"] = "负",

  ["$test3__wennie1"] = "十王垂庇，无往不胜。",
  ["$test3__wennie2"] = "罪业的气息很重啊…",
}

local yechi = fk.CreateTriggerSkill{
  name = "test3__yechi",
  frequency = Skill.Compulsory,
  events ={fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if #AimGroup:getAllTargets(data.tos) == 1 and player.id == data.from and not player.dead and not player:isNude() then
      local t = player.room:getPlayerById(data.to)
      return (t:getMark("@@test3__wennie_cheng") > 0 and t:getMark("@@test3__wennie_fu") > 0)
      and (data.card.type == Card.TypeBasic or (data.card.type == Card.TypeTrick and data.card.sub_type ~= Card.SubtypeDelayedTrick))--即时牌
    end
  end,
  on_cost = function (self, event, target, player, data)
    return #player.room:askForDiscard(player,1,1,true,self.name,true,nil,"#test3__yechi:::"..data.card:toLogString()) > 0
  end,
  on_use = function(self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + 1
  end,
}

local yechi_jl = fk.CreateDistanceSkill{
  name = "#test3__yechi_jl",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
      return 0 - to:getMark("@@test3__wennie_cheng") - to:getMark("@@test3__wennie_fu")
  end,
}

Fk:loadTranslationTable{
  ["test3__yechi"] = "业敕",
  [":test3__yechi"] = "锁定技，所有角色计算与其他角色的距离-X（X为后者拥有的“承”“负”）；一名角色使用基本牌或普通锦囊牌指定唯一目标后，若目标同时拥有“承”“负”，其可以弃置一张牌令此牌额外结算一次。",

  ["#test3__yechi_jl"] = "业敕",
  ["#test3__yechi"] = "业敕：你可以弃置一张牌令%arg额外结算一次",

  ["$test3__yechi1"] = "幽府判罚，命尔臂助……",
  ["$test3__yechi2"] = "十王敕令，在此成书。",
}


local xifu = fk.CreateTriggerSkill{
  name = "test3__xifu",
  events ={fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target
  end,
  on_cost = function (self, event, target, player, data)
    local choice = player.room:askForChoice(player,{"@@test3__wennie_cheng","@@test3__wennie_fu","Cancel"},self.name,"#test3__xifu")
    self.cost_data = {choice = choice}
    return choice ~= "Cancel"
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player,self.cost_data.choice,1)
    player.room:setPlayerMark(data.to,self.cost_data.choice,1)
  end,
  refresh_events ={fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self.name) and player:getMark("test3__wennie") ~= 0 then
      local t = player.room:getPlayerById(player:getMark("test3__wennie"))
      return (player:getMark("@@test3__wennie_cheng") > 0 and player:getMark("@@test3__wennie_fu") > 0) or
      (t:getMark("@@test3__wennie_cheng") > 0 and t:getMark("@@test3__wennie_fu") > 0)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player:setSkillUseHistory("test3__wennie",0,Player.HistoryGame)
  end,
}

Fk:loadTranslationTable{
["test3__xifu"] = "系缚",
[":test3__xifu"] = "出牌阶段，你可以于被抵消后令你与受伤者同时获得“承”或“负”；每回合结束时，若你或当前“问孽”选择的角色同时拥有“承”“负”，重置“问孽”。",

["#test3__xifu"] = "系缚：你可以与受伤角色同时获得“承”或“负”",

["$test3__xifu1"] = "束手就缚罢。",
["$test3__xifu2"] = "我代十王判罚。",
}

hanya:addSkill(wennie)
yechi:addRelatedSkill(yechi_jl)
hanya:addSkill(yechi)
hanya:addSkill(xifu)


local ruanmei = General:new(extension, "test3__ruanmei", "test_xie", 3,3, General.Female)

Fk:loadTranslationTable{
  ["test3__ruanmei"] = "阮·梅",--名字
  ["#test3__ruanmei"] = "疏影三迭",--称号
  ["designer:test3__ruanmei"] = "zuozhe",--作者
  ["cv:test3__ruanmei"] = "cv",--cv
  ["illustrator:test3__ruanmei"] = "huashi",--画师

  ['~test3__ruanmei'] = '还没有…答案……',
}

local yaoduan = fk.CreateTriggerSkill{
  name = "test3__yaoduan",
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(self.name) and player.phase == Player.Play and not player:isKongcheng()
  end,
  on_cost = function (self, event, target, player, data)
    local ids = table.filter(player:getCardIds("h"),function (c)
      return Fk:getCardById(c).suit == Card.Club
    end)
    if #ids > 0 then
      local cards,choice = U.askforChooseCardsAndChoice(player, ids, {"discard","recast"}, "test3__yaoduan", "#test3__yaoduan",{"Cancel"},1,999,player:getCardIds("h"))
      self.cost_data = {cards = cards,choice = choice}
      return choice ~= "Cancel" and #cards > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = {}
    table.forEach(self.cost_data.cards,function (element, index, array)
      table.insertIfNeed(n,Fk:getCardById(element).type)
    end)
    if self.cost_data.choice == "discard" then
      room:throwCard(self.cost_data.cards,self.name,player,player)
    else
      room:recastCard(self.cost_data.cards,player,self.name)
    end
    local ids = table.map(room:getAlivePlayers(),Util.IdMapper)
    local tishi = "#test3__yaoduan-dis:::"..#n
    if self.cost_data.choice == "recast" then
      local t = table.filter(room:getAlivePlayers(),function (p)
        return not p:isNude()
      end)
      if #t == 0 then
        return
      else
        ids = table.map(t,Util.IdMapper)
        tishi = "#test3__yaoduan-re:::"..#n
      end
    end
    local ps = room:askForChoosePlayers(player,ids,1,#n,tishi,self.name,false)
    if #ps > 0 then
      table.forEach(room:getAlivePlayers(),function (element, index, array)
        if table.contains(ps,element.id) then
          if self.cost_data.choice == "discard" then
            room:drawCards(element,#n,self.name)
          else
            room:askForDiscard(element,1,1,true,self.name,false)
          end
        end
      end)
    end
  end,
}

Fk:loadTranslationTable{
  ["test3__yaoduan"] = "摇缎",
  [":test3__yaoduan"] = "出牌阶段开始时，你可以弃置/重铸任意张梅花手牌，然后你令至多X名角色各摸X张牌/弃1张牌（X为弃置/重铸牌的类型数）。",

  ["#test3__yaoduan"] = "摇缎：你可以弃置/重铸任意张梅花手牌",
  ["#test3__yaoduan-dis"] = "摇缎：你可以令至多%arg名角色各摸%arg张牌",
  ["#test3__yaoduan-re"] = "摇缎：你可以令至多%arg名角色弃置1张牌",

  ["$test3__yaoduan1"] = "万物，本质如一。",
  ["$test3__yaoduan2"] = "无论何时盛放…",
  ["$test3__yaoduan3"] = "生命，不仅存在于呼吸之间。",
}


local shixian = fk.CreateTriggerSkill{
  name = "test3__shixian",
  events ={fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and
      player:usedSkillTimes(self.name,Player.HistoryRound) == 0 and
      #player:getTableMark("test3__shixian") < 3
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local use_data = {
      targets = table.map(room:getAlivePlayers(),Util.IdMapper),
      num = 1,
      min_num = 1,
      pattern = "",
      skillName = self.name,
      targetTipName = nil,
      extra_data = nil,
    }
    local _, ret = room:askForUseActiveSkill(player, "test3__shixian_choose", "#test3__shixian", true, use_data,false)
    if ret and ret.targets and ret.interaction then
      self.cost_data = {t = ret.targets[1], i = ret.interaction}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local t = room:getPlayerById(self.cost_data.t)
    local i = self.cost_data.i
    room:addTableMark(player,"test3__shixian",i)
    for n = 1, 2, 1 do
      if i == "#test3__shixian-1" then
        t:drawCards(2,self.name)
      elseif i == "#test3__shixian-2" then
        room:recover{
          who = t,
          num = 1,
          skillName = self.name,
          recoverBy = player,
        }
      elseif i == "#test3__shixian-3" then
        if n == 1 then
          t:turnOver()
        else
          player:turnOver()
          room:setPlayerMark(player,"test3__shixian",{"#test3__shixian-3"})
        end
      end
      if #player:getTableMark("test3__shixian") < 3 then
        break
      end
    end
  end,
  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player,"test3__shixian",0)
  end,
}

local shixian_choose = fk.CreateActiveSkill{
  name = "test3__shixian_choose",
  mute = true,
  interaction = function (self, player)
    local all = {"#test3__shixian-1","#test3__shixian-2","#test3__shixian-3"}
    local ask = table.clone(all)
    for _, v in ipairs(all) do
      if table.contains(player:getTableMark("test3__shixian"),v) then
        table.removeOne(ask,v)
      end
    end
    return UI.ComboBox{
      choices = ask,
      all_choices = all,
    }
  end,
  card_filter = function(self, to_select, selected)
    return self.pattern ~= "" and Exppattern:Parse(self.pattern):match(Fk:getCardById(to_select)) and #selected == 0
  end,
  target_filter = function(self, to_select, selected, cards)
    if self.pattern ~= "" and #cards == 0 then return end
    if #selected < self.num then
      if self.interaction.data == "#test3__shixian-2" then
        return table.contains(self.targets, to_select) and Fk:currentRoom():getPlayerById(to_select):isWounded()
      end
      return table.contains(self.targets, to_select)
    end
  end,
  target_tip = function(self, to_select, selected, selected_cards, card, selectable, extra_data)
    if self.targetTipName then
      local targetTip = Fk.target_tips[self.targetTipName]
      assert(targetTip)
      return targetTip.target_tip(self, to_select, selected, selected_cards, card, selectable, extra_data)
    end
  end,
  card_num = function(self) return self.pattern ~= "" and 1 or 0 end,
  min_target_num = function(self) return self.min_num end,
  max_target_num = function(self) return self.num end,
}



Fk:loadTranslationTable{
["test3__shixian"] = "拭弦",
[":test3__shixian"] = "每轮限一次，当你的体力值变化后，你可以令一名角色执行一项，之后移除该项：1.摸两张牌，若仅剩该项则额外执行一次；2.回复一点体力，若仅剩该项则额外执行一次；3.翻面，若仅剩该项，你翻面并重置其他所有项。",

["#test3__shixian-1"] = "摸两张牌",
["#test3__shixian-2"] = "回复1点体力",
["#test3__shixian-3"] = "翻面",

["test3__shixian_choose"] = "拭弦",
["#test3__shixian"] = "拭弦：你可以令一名角色执行一项",

["$test3__shixian1"] = "琴音，周而复始。",
["$test3__shixian2"] = "等待，亦是变化。",
["$test3__shixian3"] = "都会有被风吹落的…那一天…",
}
Fk:addSkill(shixian_choose)
ruanmei:addSkill(yaoduan)
ruanmei:addSkill(shixian)


local zhenliyisheng = General:new(extension, "test3__zhenliyisheng", "test_lie", 4)

Fk:loadTranslationTable{
  ["test3__zhenliyisheng"] = "真理医生",--名字
  ["#test3__zhenliyisheng"] = "万物皆流",--称号
  ["designer:test3__zhenliyisheng"] = "zuozhe",--作者
  ["cv:test3__zhenliyisheng"] = "cv",--cv
  ["illustrator:test3__zhenliyisheng"] = "huashi",--画师

  ['~test3__zhenliyisheng'] = '「庸人」么…呵……',
}


local lunyue_skip = fk.CreateTriggerSkill{
  name = "#test3__lunyue_skip",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("test3__lunyue-round") == 0 and data.to == Player.Play
  end,
  on_use = function (self, event, target, player, data)
    player.room:setPlayerMark(player,"test3__lunyue-round",1)
    return true
    --data.skipped = true
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player,"test3__lunyue-round",0)
  end
}

local lunyue = fk.CreateTriggerSkill{
  name = "test3__lunyue",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and #player:getTableMark("test3__lunyue-turn") > 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name)
  end,
  on_use = function (self, event, target, player, data)
    player.room:moveCards({
      ids = player:getTableMark("test3__lunyue-turn"),
      toArea = Card.DrawPile,
      moveReason = fk.ReasonPut,
      drawPilePosition = -1,
      skillName = self.name,
      proposer = player.id,
      moveVisible = true,
    })
    player:drawCards(1,self.name)
    player:gainAnExtraPhase(Player.Play,false)
  end,
  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self, true) then
      for _, move in ipairs(data) do
        local id = Fk:currentRoom():getCurrent().id
        if move.toArea == Card.DiscardPile and move.from == id and move.proposer == id then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(player.room.discard_pile, info.cardId) then
              return true
            end
          end
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile and not table.contains(player.room.discard_pile, info.cardId) then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ids = player:getTableMark("test3__lunyue-turn")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        local id = Fk:currentRoom():getCurrent().id
        for _, info in ipairs(move.moveInfo) do
          if table.contains(room.discard_pile, info.cardId) and move.from == id and move.proposer == id then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.DiscardPile and not table.contains(room.discard_pile, info.cardId) then
          table.removeOne(ids, info.cardId)
        end
      end
    end
    room:setPlayerMark(player, "test3__lunyue-turn", ids)
  end,
}

Fk:loadTranslationTable{
  ["test3__lunyue"] = "论阅",
  [":test3__lunyue"] = "锁定技，每轮限一次，你跳过出牌阶段；每回合结束时，若当前回合角色于回合内弃置过牌，你可将弃牌堆中的这些牌置于牌堆底，然后你摸一张牌并获得一个出牌阶段。",

  ["#test3__lunyue_skip"] = "论阅",

  ["$test3__lunyue1"] = "需要一些严厉的教导吗？",
  ["$test3__lunyue2"] = "由我提问了，期待各位的应答。",
}

local lizhu = fk.CreateActiveSkill{
  name = "test3__lizhu",
  switch_skill_name = "test3__lizhu",
  prompt = function (self, selected_cards, selected_targets)
    return "#test3__lizhu:::"..(Self:getSwitchSkillState(self.name) == fk.SwitchYang and "Top" or "Bottom")
  end,
  can_use = function(self, player)
    return not player:isKongcheng() and player:getMark("test3__lizhu-turn") == 0
  end,
  target_filter = Util.FalseFunc,
  card_filter = function (self, to_select, selected, player)
    return Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  min_card_num = 1,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local move = {
      ids = effect.cards,
      from = player.id,
      toArea = Card.DrawPile,
      moveReason = fk.ReasonPut,
      --drawPilePosition = -1,
      skillName = self.name,
      proposer = player.id,
      moveVisible = true,
    }
    if player:getSwitchSkillState(self.name) == fk.SwitchYang then
      move.drawPilePosition = -1
    end
    room:moveCards(move)
    local num = {}
    for i = 0, #effect.cards, 1 do
      table.insert(num,tostring(i))
    end
    local n = tonumber(room:askForChoice(player,num,self.name,"#test3__lizhu-ask:::"..(player:getSwitchSkillState(self.name) == fk.SwitchYang and "Top" or "Bottom")))
    if n > 0 then
      local cards = player:drawCards(n,self.name,player:getSwitchSkillState(self.name) == fk.SwitchYang and "top" or "bottom")
      player:showCards(cards)
      local x = #effect.cards - n
      if x < 1 then
        room:setPlayerMark(player,"test3__lizhu-turn",1)
      else
        for i = 1, x, 1 do
          local card = Fk:getCardById(cards[i])
          if not player.dead and U.getDefaultTargets(player,card,true) ~= nil and
          not table.contains(player:getTableMark("@$test3__lizhu-turn"),card.trueName) and
          (card.type == Card.TypeBasic or 
          (card.type == Card.TypeTrick and card.sub_type ~= Card.SubtypeDelayedTrick))--即时牌 
          then
            U.askForUseVirtualCard(room,player,card.name,nil,self.name,nil,false)
            room:addTableMark(player,"@$test3__lizhu-turn",card.trueName)
          end
        end
      end

    end
  end,
}

Fk:loadTranslationTable{
  ["test3__lizhu"] = "理逐",
  [":test3__lizhu"] = "转换技，出牌阶段，你可以将任意张手牌置于牌堆：阳：顶；阴：底；然后从另一端摸至多等量牌并展示之，依次视为使用前X张牌中本回合未以此法使用过的基本牌或普通锦囊牌（X为你少摸的牌数）。若X小于1，本回合此技能失效。",

  ["#test3__lizhu"] = "理逐：你可以将任意张手牌置于%arg",
  ["#test3__lizhu-ask"] = "理逐：你可以从%arg摸任意张牌",
  ["@$test3__lizhu-turn"] = "理逐",

  ["$test3__lizhu1"] = "存在，即被感知。",
  ["$test3__lizhu2"] = "定将穷尽真理，根除谬误。",
  ["$test3__lizhu3"] = "知识即为万物尺度。",
}

lunyue:addRelatedSkill(lunyue_skip)
zhenliyisheng:addSkill(lunyue)
zhenliyisheng:addSkill(lizhu)


--local xueyi = General:new(extension, "test3__xueyi", "test_hui", 3,3,General.Female)

local xueyi = General:new(extension, "test3__xueyi", "test_hui", 4,4,General.Female)

Fk:loadTranslationTable{
  ["test3__xueyi"] = "雪衣",--名字
  ["#test3__xueyi"] = "缚魔判官",--称号
  ["designer:test3__xueyi"] = "zuozhe",--作者
  ["cv:test3__xueyi"] = "cv",--cv
  ["illustrator:test3__xueyi"] = "huashi",--画师

  ['~test3__xueyi'] = '对不起，姐姐不能……',
}

local shefu = fk.CreateTriggerSkill{
  name = "test3__shefu",
  events ={fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if #AimGroup:getAllTargets(data.tos) == 1 and player:hasSkill(self.name) and data.from == player.id and
    data.card.trueName == "slash" then
      --[[
      local event_id = player.room.logic:getCurrentEvent().parent.id
      return (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        return data.card.trueName == "slash" and use.from == player.id and e.id ~= event_id
      end, Player.HistoryTurn) == 0)
      --]]
      return (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        local use = e.data[1]
        return use.from == player.id
      end, Player.HistoryTurn) == 1)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local all = {"#test3__shefu-1","#test3__shefu-2","#test3__shefu-3","#test3__shefu-4"}--,"Cancel"
    local choices = player.room:askForChoices(player,all,2,2,"test3__shefu")
    self.cost_data = {choices = choices}
    return #choices > 1
  end,
  on_use = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.test3__shefu_list = self.cost_data.choices
  end,
}

local shefu_out = fk.CreateTriggerSkill{
  name = "#test3__shefu_out",
  anim_type = "offensive",
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and
    data.extra_data and data.extra_data.test3__shefu_list and 
    (table.contains(data.extra_data.test3__shefu_list,"#test3__shefu-3") or 
      table.contains(data.extra_data.test3__shefu_list,"#test3__shefu-4"))
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local m = data.extra_data.test3__shefu_list
    --data.extra_data.test3__shefu_dixiao = true
    if table.contains(m,"#test3__shefu-3") and not to:isNude() then
      local cid = room:askForCardChosen(player, to, "he", "test3__shefu")
      room:throwCard(cid, "test3__shefu", to)
    end
    if table.contains(m,"#test3__shefu-4") then
      room:loseHp(player,1,"test3__shefu")
      if not player.dead then
        for _, v in ipairs({"#test3__shefu-1","#test3__shefu-2","#test3__shefu-3"}) do
          if player.dead then break end
          if not table.contains(m,v) then
            if v == "#test3__shefu-1" then
              if U.getDefaultTargets(player,Fk:cloneCard("slash"),true) ~= nil then
                U.askForUseVirtualCard(room,player,"slash",nil,"test3__shefu",nil,false)
              end
            elseif v == "#test3__shefu-2" then
              player:drawCards(2,"test3__shefu")
            elseif v == "#test3__shefu-3" and not to:isNude() and not to.dead then
              local cid = room:askForCardChosen(player, to, "he", "test3__shefu")
              room:throwCard(cid, "test3__shefu", to)
            end
          end
        end
      end
    end
  end,
  refresh_events = {fk.CardEffectCancelledOut},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and
    data.extra_data and data.extra_data.test3__shefu_list
  end,
  on_refresh = function(self, event, target, player, data)
    data.extra_data.test3__shefu_dixiao = true
  end,
}

local shefu_zhong = fk.CreateTriggerSkill{
  name = "#test3__shefu_zhong",
  events ={fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.from == player.id and data.card.trueName == "slash"
    and data.extra_data and data.extra_data.test3__shefu_list and not data.extra_data.test3__shefu_dixiao and
    (table.contains(data.extra_data.test3__shefu_list,"#test3__shefu-1") or 
    table.contains(data.extra_data.test3__shefu_list,"#test3__shefu-2"))
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local m = data.extra_data.test3__shefu_list
    if table.contains(m,"#test3__shefu-1") then
      if U.getDefaultTargets(player,Fk:cloneCard("slash"),true) ~= nil then
        U.askForUseVirtualCard(room,player,"slash",nil,"test3__shefu",nil,false)
      end
    end
    if table.contains(m,"#test3__shefu-2") then
      player:drawCards(2,"test3__shefu")
    end
  end,
}

Fk:loadTranslationTable{
["test3__shefu"] = "摄服",
--[":test3__shefu"] = "你于每回合首次使用【杀】指定目标后，若目标数为1，你可以秘密选择两项并于依序执行：1.若未被抵消，你视为使用一张【杀】；2.若未被抵消，你摸两张牌；3.若被抵消，你弃置目标一张牌；4.若被抵消，你失去一点体力并执行所有未选择项。",
[":test3__shefu"] = "你于回合内使用首张牌指定唯一目标后，若此牌为【杀】，你可以秘密选择两项并于依序执行：1.若未被抵消，你视为使用一张【杀】；2.若未被抵消，你摸两张牌；3.若被抵消，你弃置目标一张牌；4.若被抵消，你失去一点体力并执行所有未选择项。",

["#test3__shefu-1"] = "若未被抵消，你视为使用一张【杀】",
["#test3__shefu-2"] = "若未被抵消，你摸两张牌",
["#test3__shefu-3"] = "若被抵消，你弃置目标一张牌",
["#test3__shefu-4"] = "若被抵消，你失去一点体力并执行所有未选择项",

["#test3__shefu_out"] = "摄服",
["#test3__shefu_zhong"] = "摄服",

["$test3__shefu1"] = "束手就擒！",
["$test3__shefu2"] = "魔阴，不赦。",
}

shefu:addRelatedSkill(shefu_zhong)
shefu:addRelatedSkill(shefu_out)
xueyi:addSkill(shefu)


return extension